using System;
using System.Collections;

namespace Slaks.DocumentSerialization.TermIdInfo
{
	public class TermIdInfoList : CollectionBase
	{
		public TermIdInfoElement this[int index]
		{
			get { return ((TermIdInfoElement) List[index]); }
			set { List[index] = value; }
		}

		/// <summary>
		/// Sort thr TermIdInfoList in descending order by frequency
		/// </summary>
		public void Sort()
		{
			InnerList.Sort(new FrequencyComparer());
		}

		/// <summary>
		/// Sort the TermIdInfoList by passing custom comparator.
		/// </summary>
		/// <param name="comparator"></param>
		public void Sort(IComparer comparator)
		{
			InnerList.Sort(comparator);
		}

		public int Add(TermIdInfoElement value)
		{
			return (List.Add(value));
		}

		public int IndexOf(TermIdInfoElement value)
		{
			return (List.IndexOf(value));
		}

		public void Insert(int index, TermIdInfoElement value)
		{
			List.Insert(index, value);
		}

		public void Remove(TermIdInfoElement value)
		{
			List.Remove(value);
		}

		public bool Contains(TermIdInfoElement value)
		{
			// If value is not of type TermIdInfoElement, this will return false.
			return (List.Contains(value));
		}

		protected override void OnInsert(int index, Object value)
		{
			// Insert additional code to be run only when inserting values.
		}

		protected override void OnRemove(int index, Object value)
		{
			// Insert additional code to be run only when removing values.
		}

		protected override void OnSet(int index, Object oldValue, Object newValue)
		{
			// Insert additional code to be run only when setting values.
		}

		protected override void OnValidate(Object value)
		{
			// This check is commented out since it doesn't work for all types
			//if ( value.GetType() != Type.GetType("TermIdInfoElement") )
			//	throw new ArgumentException( "value must be of type TermIdInfoElement.", "value" );
		}
	}
}